﻿using System.Xml;
namespace com.huigo.Framework.ServiceUtils
{
    public class RequestXml
    {
        public static string GetRequestXml(RequestFunArgs XmlFunArgs)
        {
            if (!string.IsNullOrEmpty(XmlFunArgs.sFuncName.Trim()))
            {
                XmlDocument doc = new XmlDocument();
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
                doc.AppendChild(dec);
                XmlNode rootNode = doc.CreateNode(XmlNodeType.Element, "Request", null);
                doc.AppendChild(rootNode);

                XmlNode funcNode = doc.CreateNode(XmlNodeType.Element, "Func", null);
                XmlAttribute attr = doc.CreateAttribute("value");
                attr.Value = XmlFunArgs.sFuncName;
                funcNode.Attributes.Append(attr);
                rootNode.AppendChild(funcNode);

                if (XmlFunArgs.RequestArgList != null)
                {
                    foreach (var requestArg in XmlFunArgs.RequestArgList)
                    {
                        XmlElement func = doc.CreateElement(requestArg.ArgName);
                        func.InnerText = requestArg.ArgValue;
                        funcNode.AppendChild(func);
                    }
                }
                return doc.OuterXml;

            }
            return string.Empty;
        }

        //private static string GetXmlHeader()
        //{
        //    return @"<?xml version=""1.0"" encoding=""utf-8"" ?>";
        //}
        //private static string GetXmlAttr(RequestArg args)
        //{
        //    return @"<" + args.ArgName + "><![CDATA[" + args.ArgValue + "]]></" + args.ArgName + ">";
        //}
        //private static string GetFuncHeader(string sFuncName)
        //{
        //    return @"<Request><Func value=""" + sFuncName + @""">";
        //}
        //private static string GetFuncEnd()
        //{
        //    return @"</Func></Request>";
        //}
    }
}
